<!--
 * @Author: liyuxiao 1273661256@qq.com
 * @Date: 2022-06-08 15:29:43
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-03-17 21:08:41
 * @FilePath: \cscec-pms-admin\src\views\webView\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <base-breadcrumb>
    <!-- 第三方web -->
    <BaseIframe :extraAttrs="extraAttrs" v-bind="$attrs" :srcLong="srcLong" :hostUrl="hostUrl" :src="src" :isSetCookie="isSetCookie" />
  </base-breadcrumb>
</template>

<script>
import BaseIframe from '@/components/BaseIframe'
import BaseEditPage from '@/views/baseEditPage'

export default {
  name: 'a' + Date.now(),
  extends: new BaseEditPage(),
  components: {
    BaseIframe
  },
  props: {
    pathName: {
      type: String,
      default: ''
    },
    bussinessId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      src: void 0,
      hostUrl: void 0,
      isSetCookie: false,
      srcLong: null,
      extraAttrs: '',
      // 页面类型
      webType: void 0,
      hostList: {
        JX: process.env.VUE_APP_JX_BASEURL, // 绩效host
        ENTERPRISEPLANNING: process.env.VUE_APP_ENTERPRISEPLANNING_BASEURL// 企划host
      }
    }
  },
  // watch: {
  //   '$route.fullPath'() {
  //     this.getUrl()
  //   }
  // },
  activated(){
    this.getUrl()
  },
  created() {
    this.srcLong = this.fullUrl
    this.getUrl()
  },
  methods: {
    // 获取路由
    getUrl() {
      this.webType = this.$route?.meta?.webType || void 0
      if (this.webType) {
        this.bussinessId && (this.extraAttrs = `&bussinessId=${this.bussinessId}`)
        this.businessId && (this.extraAttrs = `&bussinessId=${this.businessId}`)
        this.hostUrl = this.hostList[this.webType]
        this.src = this.pathName || this.$route[this.businessId ? 'path' : 'fullPath']
        // console.log(this.hostUrl)
        // console.log(this.extraAttrs)
        // 若路由有参数则添加额外参数里
        if(Object.keys(this.$route.query)?.length){
          for(let index in this.$route.query){
            this.extraAttrs.concat(`&${index}=${this.$route.query[index]}`)
          }
        }
      }
    }
  }
}
</script>
